package com.hrm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hrm.mapper.JobMapper;
import com.hrm.pojo.DTO.JobPageDTO;
import com.hrm.pojo.Job;
import com.hrm.service.JobService;
import com.hrm.utils.entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JobServiceImpl implements JobService {
    @Autowired
    private JobMapper jobMapper;

    /**
     * 分页查询
     *
     * @param jobPageDTO
     * @return
     */
    public PageResult<Job> page(JobPageDTO jobPageDTO) {
        Page<Job> pageJob = PageHelper.startPage(jobPageDTO.getPage(), jobPageDTO.getPageSize());
        List<Job> list = jobMapper.selectLikeName(jobPageDTO.getName());
        return new PageResult<Job>(pageJob.getTotal(), list);
    }

    /**
     * 删除职位
     *
     * @param id
     * @return
     */
    public Boolean deleteById(Integer id) {
        return jobMapper.deleteByPrimaryKey(id)>0;
    }

    /**
     * 添加职位
     * @param job
     * @return
     */
    public Boolean insertJob(Job job) {
        return jobMapper.insertSelective(job)>0;
    }

    /**
     * 更新职位
     * @param job
     * @return
     */
    public Boolean updateById(Job job) {
        return jobMapper.updateByPrimaryKeySelective(job)>0;
    }

    public List<Job> getAllJob() {
        return jobMapper.getAllJob();
    }
}
